package com.originalpoint.origin_server.controller;

import com.originalpoint.origin_server.pojo.Dish;
import com.originalpoint.origin_server.pojo.Dto.BasePageDto;
import com.originalpoint.origin_server.pojo.Dto.DishDto;
import com.originalpoint.origin_server.service.DishService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    //插入
    @ApiOperation(value  = "向菜品表插入菜品信息")
    @PostMapping( "/insert")
    public void add(@RequestBody Dish dish){
        dishService.insertAll(dish);
    }
    //根据id删除
    @ApiOperation(value  = "根据id删除菜品信息")
    @GetMapping("/delete")
    public void delete(String dishid){
        dishService.deleteByDishId(Integer.valueOf(dishid));
    }
    //根据id查询
    @ApiOperation(value  = "根据id查询菜品信息")
    @GetMapping("/selectById")
    public Dish selectById(String dishid){
        return dishService.selectByDishID(Integer.valueOf(dishid));
    }
    //更新
    @ApiOperation(value  = "根据id更新菜品信息")
    @PostMapping("/update")
    public void update(@RequestBody Dish dish){
        dishService.updateDish(dish);
    }
    //分页查询，带条件
    @ApiOperation(value  = "分页查询，带条件")
    @PostMapping ("/select")
    public List<Dish> select(@RequestBody DishDto DishDto){
        return dishService.selectAllDish(DishDto);
    }
    //查询总记录，带条件
    @ApiOperation(value  = "查询总记录，带条件")
    @PostMapping("/count")
    public int count(@RequestBody DishDto dishDto){
        System.out.println(dishDto);
        return dishService.countDish(dishDto);
    }
}
